package gx.dao.impl.common;

import org.springframework.stereotype.Repository;

import gx.dao.StoreDao;
import gx.entity.Store;
import gx.entity.common.Page;
@Repository
public class StoreDaoImpl extends BaseDaoImpl<Store> implements StoreDao{

	@Override
	public Page<Store> findByWare(int pageSize, int number, String ware_name) {
		return find(pageSize,number,"from Product where name like ?","%"+ware_name+"%");
	}
//多表查询
	@Override
	public Page<Store> findByProductName(int pageSize, int number, String values) {
		
		
	//	return find(pageSize,number,"from Store where name like ?","%"+values+"%");
		return find(pageSize,number," select p.*,s.* from Store as s,Product as p where s.prod_id=p.product_id"); 
	}
	
	//将status为2 的采购purchase表里面的product信息存入store表里面。怎么写啊？
	
//入库
	@Override
	public void ruku(){
		
		//String sql="select * into Store from Purchase p where p.status==2 ";
//		Store store =new Store();
//		store.setNum(num);
//		store.setProduct(product);
//		session.save(store);
//		hql - 'select pi from   PurchaseItem pi left jion  Purcahse   p where pi.purc_id -p.id and p.status='2'"; 
//	    
//		
//		
		
		
		String sql="INSERT INTO Store(num,prod_id)"
				+ "SELECT Purchase_item.num,Purchase_item.prod_id FROM PurchaseItem,Purchase"
				+"WHERE Purchase_item.purc_id=Purchase.id AND Purchase.status='2'";
		System.out.println("ugugu");
		find(sql);
	}

}
